﻿using System.Linq;
using WeBlog.Models;

namespace WeBlog.Models
{
	public class RatingSummaryModel {
		public int Votes { get; set; }		
        public float AverageScore { get; set; }

		public RatingSummaryModel( Post post ) {

            if( !post.PostRatings.Any() ){
                Votes = 0;               
                AverageScore = 0;
            }
            else {
                Votes = post.PostRatings.Count();
                AverageScore = post.PostRatings.Average( x => x.Rating );
            }            
        }
	}
}